package com.yanqu.road.server.channelserver.webservice;

import com.alibaba.fastjson.JSONObject;
import com.yanqu.road.server.agent.AgentInterfaceMgr;
import com.yanqu.road.utils.string.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.jws.WebService;
import java.util.Objects;

@WebService
public class ChannelWebService {

    private static Logger logger = LogManager.getLogger(ChannelWebService.class.getName());

    private static final String CHECK_SIGN = "Yanqu123";

    public String executeAdminCommand(String commandName) {
        try {
            System.out.println("executeAdminCommand Called...");
            return "execute commandName: " + commandName;
        } catch (Exception ex) {
            return "";
        }
    }

    public String executeAdminOperate(String op, String param, String sign) {
        if (Objects.equals(CHECK_SIGN, sign)) {
            JSONObject ret = new JSONObject();
            ret.put("status", 0);
            ret.put("msg", "中心服务执行操作异常失败!!");
            if (!StringUtils.isNullOrEmpty(op)) {
                try {
                    return AgentInterfaceMgr.executeAgentInterface(op, param);
                } catch (Exception ex) {
                    logger.error("executeAdminOperate", ex);
                }
            }
            return ret.toString();
        }
        return "";
    }

}
